import { createStore } from 'vuex'
import type { State } from "./type"
import createPersistedState from 'vuex-persistedstate'
export default createStore<State>({
  state: {
    // 是否第一次动态添加路由
    isGetterRouter: false,
    // 是否折叠
    isCollapsed: false,
    // 用户信息
    userInfo: {
      name: "",
      gender: "",
      signature: "",
      avatar: "",
      username: "",
    },
    // 聊天框显示折叠
    isShowChat: false
  },
  getters: {},
  mutations: {
    changeGetterRouter(state, value) {
      state.isGetterRouter = value
    },
    changeCollapsed(state) {
      state.isCollapsed = !state.isCollapsed
    },
    changeUserInfo(state, value) {
      state.userInfo = {
        ...state.userInfo,
        ...value,
      }
    },
    clearUserInfo(state) {
      state.userInfo = {
        name: "",
        gender: "",
        signature: "",
        avatar: "",
        username: "",
      }
    },
    changeisShow(state, isShow) {
      state.isShowChat = isShow
    }
  },
  actions: {},
  modules: {},
  // 实现vue持久化
  plugins: [
    createPersistedState({
      paths: ['isCollapsed', 'userInfo'], //控制是否持久化
    }),
  ],
})
